package com.example.demo.controller;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.example.demo.pojo.PassengerFlow;
import com.example.demo.service.PassengerFlowService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project:demo
 * @Description: .
 * @Author: Mr.Hunter
 * @Date:2023/3/28/20:50
 */
@Slf4j
@RestController
@RequestMapping("/PassengerFlow")
public class PassengerFlowController {
    @Autowired
    private PassengerFlowService passengerFlowService;
    @Resource
    private RestTemplate restTemplate;
    @Value("http://paiban")
    private String serverURL;

    @ApiOperation("查找所有的预测客流量")
    @GetMapping("/findAll")
    public String findAllPassengerFlow() {
        return restTemplate.getForObject(serverURL + "/passenger_flow/findAll", String.class);
    }

    @ApiOperation("查找指定门店的预测客流量")
    @GetMapping("/find/{shopid}")
    public String findPassengerFlowById(@PathVariable("shopid") Integer shopid) {
        return restTemplate.getForObject(serverURL + "/passenger_flow/passenger/" + shopid, String.class);
    }

    @ApiOperation("查找指定门店的预测客流量")
    @GetMapping("/find/{shopid}/{date}")
    public String findPassengerFlowByIdAndDate(@PathVariable("shopid") Integer shopid, @PathVariable("date") String date) {
        return restTemplate.getForObject(serverURL + "/passenger_flow/passenger/" + shopid + "/" + date, String.class);
    }

    @ApiOperation("查找指定门店的某一天预测客流量(这里日期填写形如yyyyMMdd)【🐏】")
    @GetMapping("/selectAllByDateAndShopID/{shopID}/{date}")
    public List<PassengerFlow> selectAllByDateAndShopID(@PathVariable("shopID") Integer shopID, @PathVariable("date") String date) {
        return  passengerFlowService.selectAllByDateAndShopID(date,shopID);
    }


}